﻿using Sustainalytics.Claims;
using Sustainalytics.ClientDW.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;

namespace Sustainalytics.GCCS.Service.Controllers
{
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    //[AutoInvalidateCacheOutput]
    [RoutePrefix("api/v1/gcprincipleeventindicatorimpact")]
    public class GCPrincipleEventIndicatorImpactController : ApiController
    {
        IGCPrincipleEventIndicatorImpactManager _manager;
        IClaimsChecker _claimsChecker;

        public GCPrincipleEventIndicatorImpactController(IGCPrincipleEventIndicatorImpactManager manager, IClaimsChecker claimsChecker)
        {
            _manager = manager;
            _claimsChecker = claimsChecker;
        }


       // [CacheOutput(ServerTimeSpan = 100, ClientTimeSpan = 0, NoCache = true, MustRevalidate = true, Private = true)]
        [Route("")]
        public HttpResponseMessage Get(Guid principleSummaryId)
        {
            if (!_claimsChecker.ValidateNonCompliantOrWatchlist(this))
            {
                return this.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }

            // get principle event indicators impact
            List<GCPrincipleEventIndicatorImpact> lst = _manager.GetList(principleSummaryId);

            // project to DTO
            List<GCPrincipleEventIndicatorImpactDto> dtos = lst.Select(el => new GCPrincipleEventIndicatorImpactDto().LoadFrom(el)).ToList();

            return this.Request.CreateResponse(HttpStatusCode.OK, dtos);
        }
    }
}
